package handler

import (
	"comment-master/model"

	"github.com/gin-gonic/gin"
)

func User(c *gin.Context) {

	username := c.PostForm("username")
	password := c.PostForm("password")
	if username == "" || password == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段为空",
		})
		return
	}

	var u model.User
	u.Username = username
	u.Password = password
	err := model.DB.Create(&u).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return

}

func Cctv(c *gin.Context) {

	var v []model.Cctv

	err := model.DB.Find(&v).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "列表失败",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "列表成功",
	})
	return

}
